<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright Artur Figueira 2009 <arturfigueira@gmail.com> -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="UTF-8" method="xml"/>

<xsl:template match="workflow" name="amethyst_XPDL_Header">
	<xsl:variable name="WORKFLOW_NAME"><xsl:value-of select="@name" /></xsl:variable>
	<xsl:variable name="WORKFLOW_ID"><xsl:value-of select="@id" /></xsl:variable>
	<!-- <Package Id="{$WORKFLOW_ID}" Name="{$WORKFLOW_NAME}" xsi:schemaLocation="http://www.wfmc.org/2004/XPDL2.0alpha http://www.wfmc.org/standards/docs/TC-1025_bpmnxpdl_24.xsd" xmlns:deprecated="http://www.wfmc.org/2002/XPDL1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.wfmc.org/2004/XPDL2.0alpha"> -->
	<Package Id="{$WORKFLOW_ID}" Name="{$WORKFLOW_NAME}" xsi:schemaLocation="http://www.wfmc.org/standards/docs/TC-1025_bpmnxpdl_24.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
		<xsl:call-template name="amethyst_XPDL_PackageHeader" />
		<xsl:call-template name="amethyst_XPDL_Participants" />
		<xsl:call-template name="amethyst_XPDL_Pools" />
		<xsl:call-template name="amethyst_XPDL_WorkflowProcess" />
	</Package>
</xsl:template>

<xsl:template name="amethyst_XPDL_PackageHeader">
	<PackageHeader>
		<XPDLVersion>2.0</XPDLVersion>
		<Vendor>Auto Generated By Amethyst Workflow Processor</Vendor>
	</PackageHeader>
</xsl:template>

<xsl:template name="amethyst_XPDL_Participants">
<!-- TODO -->
</xsl:template>

<xsl:template name="amethyst_XPDL_Pools">
<!-- TODO -->
</xsl:template>

<xsl:template name="amethyst_XPDL_WorkflowProcess">
	<WorkflowProcesses>
		<WorkflowProcess Id="WFP_0" Name="Workflow Process 0" AccessLevel="PUBLIC" ProcessType="NONE" status="NONE" SuppressJoinFailure="false" EnableInstanceCompensation="false" AdHoc="false" AdHocOrdering="PARALLEL">
			<xsl:call-template name="amethyst_XPDL_Activities" />
			<xsl:call-template name="amethyst_XPDL_Transitions" />
		</WorkflowProcess>
	</WorkflowProcesses>
</xsl:template>


<xsl:template name="amethyst_XPDL_Activities">
	<Activities>
		<xsl:for-each select="module">
			<xsl:sort select="@id" order="ascending"/><!-- TODO..check if its true -->
			<xsl:variable name="MODULE_NAME"><xsl:value-of select="@name" /></xsl:variable>
			<xsl:variable name="MODULE_ID"><xsl:value-of select="@id" /></xsl:variable>
			<xsl:variable name="MODULE_X_COORD"><xsl:value-of select="location/@x" /></xsl:variable>
			<xsl:variable name="MODULE_Y_COORD"><xsl:value-of select="location/@y" /></xsl:variable>
			<Activity Id="{$MODULE_ID}" Name="{$MODULE_NAME}" Status="None" StartMode="Automatic" FinishMode="Automatic">
				
				<!-- First Module It's the StartEvent -->
				<xsl:if test="position() = 1">
					<Event>
						<StartEvent Trigger="None" />
					</Event>
				</xsl:if>
				
				<!-- Last Event. It's the End Event -->
				<xsl:if test="position() = last()">
					<Event>
						<EndEvent Result="None" />
					</Event>
				</xsl:if>
				
				<NodeGraphicsInfos>
					<!-- <NodeGraphicsInfo ToolId="BXModeller" Page="WFP_0" LaneId="LNE_0" Height="25.0" Width="25.0">--><!-- TODO -->
					<NodeGraphicsInfo>
						<Coordinates XCoordinate="{$MODULE_X_COORD}" YCoordinate="{$MODULE_Y_COORD}" />
					</NodeGraphicsInfo>
				</NodeGraphicsInfos>
				
			</Activity>
		</xsl:for-each>
	</Activities>
</xsl:template>


<xsl:template name="amethyst_XPDL_Transitions">
	<Transitions>
		<xsl:for-each select="connection">
			<xsl:variable name="TRANSITION_ID"><xsl:value-of select="@id" /></xsl:variable>
			<xsl:variable name="TRANSITION_FROM"><xsl:value-of select="port[@type='source']/@moduleId" /></xsl:variable>
			<xsl:variable name="TRANSITION_TO"><xsl:value-of select="port[@type='destination']/@moduleId" /></xsl:variable>
			<Transition Id="{$TRANSITION_ID}" Name="trns_{$TRANSITION_ID}" From="{$TRANSITION_FROM}" To="{$TRANSITION_TO}">
				<!-- TODO -->
			</Transition>
		</xsl:for-each>
	</Transitions>
</xsl:template>

</xsl:stylesheet> 